package com.leonzhangxf.spel.reference;

import org.springframework.expression.spel.SpelParserConfiguration;
import org.springframework.expression.spel.standard.SpelExpressionParser;

/**
 * Types
 * <p>
 * You can use the special T operator to specify an instance of java.lang.Class (the type).
 * Static methods are invoked by using this operator as well.
 * The StandardEvaluationContext uses a TypeLocator to find types,
 * and the StandardTypeLocator (which can be replaced) is built with an understanding of the java.lang package.
 * This means that T() references to types within java.lang do not need to be fully qualified,
 * but all other type references must be.
 *
 * @author leonzhangxf
 * @date 20190427
 */
public class Types {

    public static void main(String[] args) {
        SpelParserConfiguration parserConfiguration =
            new SpelParserConfiguration(true, true);
        SpelExpressionParser parser = new SpelExpressionParser(parserConfiguration);

        System.out.println(parser.parseExpression("T(java.util.Date)").getValue(Class.class));

        System.out.println(parser.parseExpression("T(String)").getValue(Class.class));

        System.out.println(parser
            .parseExpression("T(java.math.RoundingMode).CEILING < T(java.math.RoundingMode).FLOOR")
            .getValue(Boolean.class));
    }
}
